﻿<%@ Page Title="" Language="C#" MasterPageFile="~/administrator/backend.Master" AutoEventWireup="true" CodeBehind="role-add.aspx.cs" Inherits="VQWEB.administrator.membership.role_add" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Content_backend" runat="server">
    <form id="frm_roles" role="form" runat="server">
    <asp:FormView runat="server" ID="frmRoles" RenderOuterTable="false">
        <EditItemTemplate>
            <div class="form-group">
                <label>
                    Roles Name</label>
                <input type="text" class="form-control" name="role_name" value='<%# Eval("role_name") %>'>
            </div>            
            <input type="hidden" name="role_id" value='<%# (Eval("role_id") != null) ? Eval("role_id") : "0" %>' />
            <div class="table-responsive">
                <asp:ListView runat="server" ID="lvModules" OnItemDataBound="lvModules_ItemDataBound">
                    <LayoutTemplate>
                        <table class="table table-bordered table-hover">
                            <thead>
                                <tr class="active">
                                    <th>
                                        #
                                    </th>
                                    <th>
                                        <input type="checkbox" name="chkAll" value="" />
                                    </th>
                                    <th>
                                        Modules Name
                                    </th>
                                    <th>
                                        Modules Code
                                    </th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr id="ItemPlaceholder" runat="server">
                                </tr>
                            </tbody>
                        </table>
                    </LayoutTemplate>
                    <ItemTemplate>
                        <tr>
                            <td>
                                <%# Container.DataItemIndex + 1 %>
                            </td>
                            <td>
                                <asp:Literal ID="ltrItem" runat="server"></asp:Literal>
                            </td>
                            <td>
                                <%# Eval("title")%>
                            </td>
                            <td class="module_code">
                                <%# Eval("name")%>
                            </td>
                        </tr>
                    </ItemTemplate>
                </asp:ListView>
            </div>
        </EditItemTemplate>
    </asp:FormView>
    </form>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="Script_backend" runat="server">
    <script type="text/javascript">
        ShowToolBar("edit");
        var url_ashx = "/admin/membership/handler";
        $("#btnCancel").live("click", function () {
            window.location = "/admin/membership/role/list";
        });

        $("#btnSave").live("click", function () {
            var role_name = $(":input[name='role_name']").val();
            var arr = $("#frm_roles").serializeObject();
            $.post(url_ashx, { post_roles: arr }, function (data) {
                alert(data);
                window.location = "/admin/membership/role/list";
            });

        });

        //Check All item in table
        $(":input[name='chkAll']").live("click", function () {
            if ($(this).prop("checked")) {
                $(':input[name="module[]"]').each(function () {
                    $(this).prop("checked", true);
                });
            } else {
                $(':input[name="module[]"]').each(function (item) {
                    $(this).prop("checked", false);
                });
            }
        });
        
    </script>
</asp:Content>
